package com.truthbean.jeetb.cms.sys.handler;

import com.truthbean.jeetb.model.sys.entity.User;

import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import java.io.Serializable;

/**
 * Created by TruthBean on 2016-10-09 17:21.
 */
@SessionScoped
public class LoginHandler implements Serializable {

    //Get the request scoped Credentials associated
    //with this user.
    @Inject
    private User user;

    private boolean login = false;

    public void login() {
        //For this sample, just check whether a
        //non-empty username and password is provided
        //and allow successful login
        if (user.getName() != null &&
                user.getName().trim().length() > 0 &&
                user.getPassword() != null &&
                user.getPassword().trim().length() > 0) {
            login = true;
        }
    }

    public boolean isLogin() {
        return login;
    }

    public void logout() {
        login = false;
    }
}
